﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Escuela.Forms
{
    public partial class AlumnosMorosos : Form
    {
        private Instituto inst;
        public AlumnosMorosos(Instituto inst)
        {
            InitializeComponent();
            this.inst = inst;
        }

        private void AlumnosMorosos_Load(object sender, EventArgs e)
        {
            try
            {
                // TODO: This line of code loads data into the 'escuelaDataSet5.coop_pago_GetMorosos' table. You can move, or remove it, as needed.
                this.coop_pago_GetMorososTableAdapter.Fill(this.escuelaDataSet5.coop_pago_GetMorosos);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error cargando formulario. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void Actualizar_Click(object sender, EventArgs e)
        {
            try
            {
                // TODO: This line of code loads data into the 'escuelaDataSet5.coop_pago_GetMorosos' table. You can move, or remove it, as needed.
                this.coop_pago_GetMorososTableAdapter.Fill(this.escuelaDataSet5.coop_pago_GetMorosos);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error actualizando alumnos morosos. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void Cancelar_Click(object sender, EventArgs e)
        {
            try
            {
                //genero excel
                string ruta = this.inst.EnviarExcelPorMail(this.dataGridView1);
                EnviarMail em = new EnviarMail(this.inst, ruta);
                em.ShowDialog();
                MessageBox.Show("Informe enviado con exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch(Exception ex)
            {
                MessageBox.Show("Error enviando informe por mail. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                foreach (DataGridViewRow dr in dataGridView1.Rows)
                {
                    try
                    {
                        string mail = dr.Cells[9].Value.ToString();
                        this.inst.enviarmailDeuda(mail);
                    }
                    catch
                    {

                    }
                    
                }
                MessageBox.Show("Mails de aviso enviados correctamente", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error enviando notificaciones", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void Aceptar_Click(object sender, EventArgs e)
        {
            try
            {
                this.inst.ExcelMorosos(this.dataGridView1);
                MessageBox.Show("Excel generado con exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error exportando excel. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        
    }
}
